﻿using System;
/// <summary>
/// model.Item 참고.
/// </summary>
public class Item
{    
    int m_Id;
    public int id
    {
        get { return m_Id; }
        set
        {
            m_Id = value;
            SetInfo();
        }
    }

    public short itemType;      // 1오른쪽 2 왼쪽
    public short m_level;			// 강화레벨 
    public short level
    {
        get { return m_level; }
        set
        {
            m_level = value;
            SetEffectValue();
        }
    }
    public short amount;
    public short strengFailCount;	// 강화실패 횟수

    [NonSerialized]
    public DItem itemInfo;

    [NonSerialized]
    public int effectValue01;

    [NonSerialized]
    public int effectValue02;

    void SetInfo()
    {
        for(int i = 0 ; i < GameData.Inst.item.Length ; i++)
        {
            if(id == GameData.Inst.item[i].itemID)
            {
                itemInfo = GameData.Inst.item[i];
                break;
            }
        }
    }

    void SetEffectValue()
    {
        if (itemInfo != null)
        {
            if (itemInfo.effectType1 > 0)
                effectValue01 = GetItemEffectValueWithLevel(this, level, 1);

            if (itemInfo.effectType2 > 0)
                effectValue02 = GetItemEffectValueWithLevel(this, level, 2);
        }
    }

    static public int GetItemEffectValueWithLevel(Item pItem, int plevel, int pEffectNum)
    {
        int a = 0;
        int s = 0;
        float b = 0;
        float c = 0;

        if (pEffectNum == 1)
        {
            a = pItem.itemInfo.effectValue1a;
            b = pItem.itemInfo.effectValue1b;
            c = pItem.itemInfo.effectValue1c;
            s = pItem.itemInfo.effectValue1;
        }
        else if (pEffectNum == 2)
        {
            a = pItem.itemInfo.effectValue2a;
            b = pItem.itemInfo.effectValue2b;
            c = pItem.itemInfo.effectValue2c;
            s = pItem.itemInfo.effectValue2;
        }

        return s + (int)(a * Math.Pow((plevel + b), c));
    }
}
